<template>
	<div class="warp shareMain">
		<open-app ref="openApp"></open-app>
		<p class="header"><a href="javascript:void(0)" @click="back()"><i></i></a>{{storeInfo.name}}</p>
		<div class="banner">
			<a href="javascript:;" @click="openApp"><img src="../assets/images/banner.jpg"></a>
		</div>
		<div class="title">
			<img :src="storeInfo.logo|imgDomain">
			<p class="p1">{{storeInfo.name}}</p>
			<p class="p2">{{storeInfo.businessCategoryName}}</p>
		</div>
		<div class="address shareItem">
			<div class="add" @click="openApp"><i></i>{{region}}{{storeInfo.address}}</div>
			<div class="tel">
				<a href="javascript:;" @click="openApp"><i></i></a>
			</div>
		</div>

		<div class="sell shareItem" v-if="goodsNum>0">
			<p class="shartTitle"><i></i>本店在售</p>
			<ul>
				<li v-for="(product, key) in productList" :key="key">
					<router-link :to="{name: 'ShareGoods', query:{productUID: product.uniqueID, salesOutletUID: getSalesOutletUID()}}">
						<img :src="product.firstPic|imgDomain">
						<p class="p1">{{product.name}}</p>
						<p class="p2">{{$t('message.currency')}}{{product.defaultPrice|toDecimal}}</p>
					</router-link>
				</li>
			</ul>
			<p class="more"><a href="javascript:;" @click="openApp">共{{goodsNum}}款</a></p>
		</div>

		<div class="time shareItem">
			<p class="shartTitle">服务信息</p>
			<ul>
				<li>营业时间<span>{{storeInfo.openTime|formatTime}}-{{storeInfo.closeTime|formatTime}}</span></li>
				<li>配送时间<span>{{storeInfo.deliveryTimeRange}}</span></li>
			</ul>
		</div>

		<div class="about shareItem">
			<p class="shartTitle">商家信息</p>
			<div class="info">
				{{storeInfo.introduction}}
			</div>
		</div>
	</div>
</template>
<script>
import openApp from './OpenApp'
import tool from '../tools/tool'

export default {
	components: {
		openApp
	},
	data () {
		return {
			storeInfo: {},
			status: false,
			productList: [],
			goodsNum: 0,
			region: '',
			salesOutletUID: this.$route.query.salesOutletUID
		}
	},
	created () {
		this.getStoreInfo();
		//this.getRegion(22,237,2317);
	},
	methods: {
		getSalesOutletUID () {
			return this.salesOutletUID
		},
		getStoreInfo () {
			if (this.status) return true;
			if (!this.salesOutletUID) {
				alert("该连接无效")
				return false
			}
			this.$http.post('/api/store', { suid: this.salesOutletUID }).then(res => {
				if (res.body.error != "") {
					alert(res.body.error);
				} else {
					this.storeInfo = res.body.resData;
					let closeTime = Math.floor(this.storeInfo.closeTime * 100) / 100;
					this.productList = this.storeInfo.productList
					this.goodsNum = this.productList.length;
					if (this.goodsNum > 5) {
						this.goodsNum = 5
						this.productList = this.productList.slice(0, 5)
					}
					//console.log(this.productList)
					for (let i = 0; i < this.productList.length; i++) {
						if (this.productList[i].productPictures != null)
							this.productList[i].firstPic = this.productList[i].productPictures.split(";")[0]
					}
					this.getRegion(this.storeInfo.province, this.storeInfo.city, this.storeInfo.province)
					//this.getProductList(this.salesOutletUID);
					this.status = true;
				}
			}, res => {

			})
			this.checkStoreStatus = true;
			return true;
		},
		getProductList (salesOutletUID) {
			this.$http.post('/api/getProductList', { suid: salesOutletUID }).then(res => {
				const result = res.data
				if (result.resData) {
					this.productList = result.resData.list
				} else {
					console.log('该门店下无商品：' + result.description)
				}
			}, res => {

			})
			this.goodsNum = this.productList.length;
		},
		getRegion (p_code, c_code, d_code) {
			this.$http.post('/api/getRegion').then(res => {
				const result = res.data
				if (result.resData) {
					const regionList = JSON.parse(result.resData)
					const regionChina = regionList.CountryRegion[0]
					for (let pid = 0; pid < regionChina.State.length; pid++) {

						if (regionChina.State[pid].Code == p_code) {
							this.region = regionChina.State[pid].Name
							const province = regionChina.State[pid]

							for (let cid = 0; cid < province.City.length; cid++) {
								if (province.City[cid].Code == c_code) {
									this.region += province.City[cid].Name
									const city = province.City[cid]

									for (let did = 0; did < city.Region.length; did++) {
										if (city.Region[did].Code == d_code) {
											this.region += city.Region[did].Name
										} else {
											continue
										}
										break;
									}

								} else {
									continue
								}
								break;
							}
						} else {
							continue
						}
						break;
					}
				} else {
					console.log('该门店下无商品：' + result.description)
				}
			}, res => {

			})
		},
		openApp () {
			let shareOptions = [
				{ 'field': 'salesOutletUID', 'value': this.salesOutletUID },
			]
			this.$refs.openApp.openApp(shareOptions, 'shop')
		},
		back () {
			// console.log(history)
			if (history.length >= 3) {
				this.$router.back()
			} else {
				this.$router.push({ name: 'Register', query: { salesOutletUID: this.salesOutletUID } })
			}
		}
	},
	filters: {
		// 补全图片路径
		imgFilter (val) {
			let url = 'http://imgnew.e-gatenet.cn/' + val
			return url
		},
		formatPrice (val) {// 格式化价格
			return Math.floor(val * 100) / 100
		},
		toDecimal (x) {
			var f = parseFloat(x);
			if (isNaN(f)) {
				return false;
			}
			var f = Math.round(x * 100) / 100;
			var s = f.toString();
			var rs = s.indexOf('.');
			if (rs < 0) {
				rs = s.length;
				s += '.';
			}
			while (s.length <= rs + 2) {
				s += '0';
			}
			return s;
		},
		formatTime (timeFloat) { // time为小数
			let time = Math.floor(timeFloat * 100) / 100;
			//时间小于10,前缀补充0或者后缀补充0
			let timePre = (t, flag = false) => {
				if (t < 10) {
					if (flag) {
						if (t[0] != '0') {
							t = t + '0'
						}
					} else {
						t = '0' + t
					}

				}
				return t;
			}
			if (Math.floor(time) == time) { //整点型的
				if (time > 24) {
					return `次日${timePre(time - 24)}:00`
				} else if (time == 24) {
					return `次日00:00`
				}
				return `${timePre(time)}:00`
			} else {
				let timeStr = time.toString()
				let timeArr = timeStr.split(".");
				if (timeArr[0] > 24) {
					return `次日${timePre(timeArr[0] - 24)}:${timePre(timeArr[1], true)}`
				} else if (timeArr[0] == 24) {
					return `次日00:${timePre(timeArr[1], true)}`
				}
				return `${timePre(timeArr[0])}:${timePre(timeArr[1], true)}`
			}
		}
	}
}
</script>
<style scoped>
@charset "utf-8";

/* 样式重置 */
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
font,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  background: transparent;
  color: #474747;
  font-family: 'MicrosoftYaHei';
}
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
input,
textarea {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  color: #474747;
  font-family: 'MicrosoftYaHei';
}
body {
  line-height: 1.5;
}
ol,
ul,
li {
  list-style: none;
}
blockquote,
q {
  quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
  content: '';
  content: none;
}
:focus {
  outline: 0;
}
ins {
  text-decoration: none;
}
del {
  text-decoration: line-through;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
  background-color: #fff;
}
a {
  cursor: pointer;
  text-decoration: none;
  color: #9b9b9b;
}
img {
  vertical-align: bottom;
}
i {
  font-style: normal;
  color: #666;
}
input[type='text'] {
  -webkit-appearance: none;
}
textarea {
  -webkit-appearance: none;
}
a,
img,
button,
input,
textarea,
label,
div {
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}
/* 单独的清除元素*/
.clear {
  clear: both;
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}

/* 当一个外部元素内部有浮动元素时，外部元素如需清除浮动，用如下的清除样式 */
.clearfix:after {
  clear: both;
  content: '.';
  display: block;
  visibility: hidden;
  height: 0;
}
.clearfix {
  display: inline-block;
}
* html .clearfix {
  height: 1%;
}
.clearfix {
  display: block;
}
* + html .clearfix {
  min-height: 1%;
}

body,
html {
  background: #f0f0f0;
  height: 100%;
}

.warp {
  width: 100%;
  max-width: 750px;
  position: relative;
  margin: auto;
  background: #f0f0f0;
}

.shareMain .header {
  text-align: center;
  font-size: 0.36rem;
  color: #181818;
  line-height: 0.8rem;
  position: relative;
  background: #fff;
}
.shareMain .header a {
  position: absolute;
  left: 0;
  top: 0;
  height: 0.8rem;
  width: 0.8rem;
}
.shareMain .header a i {
  width: 0.18rem;
  height: 0.34rem;
  background: url('../assets/images/back.png') no-repeat;
  background-size: 100%;
  display: block;
  margin: auto;
  margin-top: 0.23rem;
}

.shareMain .banner img {
  width: 100%;
}
.shareMain .title {
  position: relative;
  padding: 0.4rem;
  padding-left: 1.8rem;
}
.shareMain .title img {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  position: absolute;
  left: 0.5rem;
}
.shareMain .title .p1 {
  font-size: 0.3rem;
  color: #181818;
  line-height: 0.5rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.shareMain .title .p2 {
  font-size: 0.28rem;
  color: #555555;
  line-height: 0.5rem;
}
.shareMain .time ul {
  padding: 0 0.26rem;
  overflow: hidden;
  margin-bottom: 0.2rem;
}
.shareMain .time ul li {
  font-size: 0.28rem;
  color: #181818;
  line-height: 0.88rem;
  border-bottom: #e1e1e1 solid 0.01rem;
}
.shareMain .time ul li:last-child {
  border-bottom: none;
}
.shareMain .time ul li span {
  float: right;
}
.shareMain .about .info {
  font-size: 0.26rem;
  color: #666666;
  padding: 0.26rem;
}

.shareMain .address {
  padding: 0.24rem 0;
  position: relative;
  font-size: 0.28rem;
  min-height: 0.6rem;
}
.shareMain .address .add {
  color: #181818;
  padding-left: 0.7rem;
  padding-right: 1.2rem;
  line-height: 0.5rem;
}
.shareMain .address .add i {
  width: 0.28rem;
  height: 0.32rem;
  background: url('../assets/images/address.png') no-repeat;
  background-size: 100%;
  display: block;
  position: absolute;
  margin-left: -0.4rem;
  top: 0.34rem;
}
.shareMain .address .tel {
  position: absolute;
  right: 0;
  top: 50%;
  width: 1.1rem;
  height: 0.6rem;
  border-left: #ddd solid 0.01rem;
  margin-top: -0.3rem;
}
.shareMain .address .tel a {
  display: block;
  height: 0.48rem;
  padding-top: 0.12rem;
}
.shareMain .address .tel i {
  width: 0.36rem;
  height: 0.37rem;
  background: url('../assets/images/tel.png') no-repeat;
  background-size: 100%;
  display: block;
  margin: auto;
}

.shareMain .sell .shartTitle {
  padding-left: 0.82rem;
  position: relative;
}
.shareMain .sell .shartTitle i {
  width: 0.34rem;
  height: 0.34rem;
  background: url('../assets/images/share.png') no-repeat;
  background-size: 100%;
  display: block;
  position: absolute;
  left: 0.3rem;
  top: 0.26rem;
}
.shareMain .sell ul {
  padding: 0 0.3rem;
}
.shareMain .sell ul li {
  position: relative;
  padding: 0.2rem 0;
  padding-left: 1.2rem;
  border-bottom: #e1e1e1 solid 0.01rem;
}
.shareMain .sell ul li:last-child {
  border-bottom: none;
}
.shareMain .sell ul li img {
  width: 1rem;
  height: 1rem;
  position: absolute;
  left: 0;
}
.shareMain .sell ul li .p1 {
  font-size: 0.26rem;
  color: #323232;
  line-height: 0.5rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.shareMain .sell ul li .p2 {
  font-size: 0.26rem;
  color: #09bebf;
  line-height: 0.5rem;
}
.shareMain .sell .more {
  text-align: center;
  line-height: 0.66rem;
  border-top: #e1e1e1 solid 0.01rem;
}
.shareMain .sell .more a {
  display: block;
  font-size: 0.22rem;
  color: #777777;
}

.shareMain .show {
  margin-top: 0.1rem;
}
.shareMain .show img {
  width: 100%;
}
.shareMain .showTitle {
  background: #fff;
  margin-bottom: 0.2rem;
  padding: 0.26rem 0.5rem;
}
.shareMain .showTitle .p1 {
  font-size: 0.3rem;
  color: #181818;
  line-height: 0.5rem;
}
.shareMain .showTitle .p2 {
  font-size: 0.28rem;
  color: #09bebf;
  line-height: 0.5rem;
}
.shareMain .shareItem {
  background: #fff;
  margin-bottom: 0.2rem;
}
.shareMain .shartTitle {
  font-size: 0.28rem;
  color: #181818;
  line-height: 0.88rem;
  padding-left: 0.26rem;
  border-bottom: #e1e1e1 solid 0.01rem;
}
</style>